from sqlmodel import SQLModel, Field, Index
from datetime import datetime

class SwapStat(SQLModel, table=True):
    """Waveup交易对表数据库模型"""
    __tablename__ = "t_swap_stat"  # 对应数据库表名

    # 索引定义（优化查询性能）
    __table_args__ = (
        Index("idx_uid_productPairId", "uid", "productPairId", info="用户ID-交易对编码索引"),
    )

    # 字段定义
    id: int = Field(default=None, primary_key=True, index=True)
    uid: int = Field(index=True, description="用户ID")
    productPairId: str = Field(index=True, description="交易对编码")
    swapCount: int = Field(default=0, description="兑换次数")
    swapAmount: float = Field(default=0.0, description="兑换金额")
    createdAt: datetime = Field(default_factory=datetime.now, description="创建时间")
    updatedAt: datetime = Field(default_factory=datetime.now, description="更新时间")